@section Header {
    @Html.Partial("_IndexHeader")
}  

@if(Context.Bool(BlogKeys.IndexFullPosts))
{
    foreach(IDocument post in Model.DocumentList(Keys.PageDocuments))
    {
        string lead = post.String(BlogKeys.Lead);
        <h2>@post.WithoutSettings.String(BlogKeys.Title)</h2>
        @if(!string.IsNullOrWhiteSpace(lead))
        {
            <p>@lead</p>
        }
        <hr />
        <p><em>Posted on @(post.Get<DateTime>(BlogKeys.Published).ToLongDateString(Context))</em></p>
        @Html.Raw(post.Content)
    }
}
else
{
    <section class="features">
        @foreach(IDocument post in Model.DocumentList(Keys.PageDocuments))
        {
            string lead = post.String(BlogKeys.Lead);
            <article>
                <h3>@post.WithoutSettings.String(BlogKeys.Title)</h3>
                @if(!string.IsNullOrWhiteSpace(lead))
                {
                    <p>@lead</p>
                }
                <hr />                            
                <p><em>Posted on @(post.Get<DateTime>(BlogKeys.Published).ToLongDateString(Context))</em></p>
                @Html.Raw(post.String(BlogKeys.Excerpt))
                <a href="@Context.GetLink(post)" class="special">Read</a>
            </article>
        }
    </section>
}
<ul class="actions">           
    @if(Model.Bool(Keys.HasPreviousPage))
    {
        <li>
            <a href="@(Context.GetLink(Model.Document(Keys.PreviousPage)))" class="button"><span aria-hidden="true">&larr;</span> Newer</a>
        </li>
    }    
    @if(Model.Bool(Keys.HasNextPage))
    {
        <li>
            <a href="@(Context.GetLink(Model.Document(Keys.NextPage)))" class="button">Older <span aria-hidden="true">&rarr;</span></a>
        </li>
    }
</ul>

@section Sections {
    @if(Documents[Blog.Tags].Any())
    {
        <section class="wrapper alt style3">
            <div class="inner">
                <h5 class="major">Tags</h5>
                <div>
                    @foreach (IDocument tagDocument in Documents[Blog.Tags]
                        .GroupBy(x => x.String(BlogKeys.Tag)).Select(x => x.Where(p => p.Get<int>(Keys.CurrentPage) == 1).First())
                        .OrderByDescending(x => x.Get<int>(Keys.TotalItems)).Take(10))
                    {
                        string tag = tagDocument.String(BlogKeys.Tag);
                        string postCount = tagDocument.String(Keys.TotalItems);
                        <a href="@Context.GetLink(tagDocument)" role="button" class="button small"> @tag (@postCount)</a>
                    }
                </div>
                <br />
                <ul class="actions">
                    <li>
                        <a href="@Context.GetLink("tags/index.html")" class="button">View All Tags &rarr;</a>
                    </li>
                </ul>
            </div>
        </section>
    }
    @if(!Context.Bool(BlogKeys.IndexPaging))
    {
        <section class="wrapper style1">
            <div class="inner">
                <h5 class="major">Older Posts</h5>
                <ul>
                    @foreach(IDocument doc in Documents[Blog.BlogPosts].Skip(Model.DocumentList(Keys.PageDocuments).Count).Take(4))
                    {        
                        <li><a href="@Context.GetLink(doc)">@doc.WithoutSettings.String(BlogKeys.Title)</a></li>
                    }
                </ul>
                @if(Context.Bool(BlogKeys.GenerateArchive))
                {
                    <ul class="actions">
                        <li>
                            <a href="@Context.GetLink(Context.String(BlogKeys.PostsPath))" class="button">Archive &rarr;</a>
                        </li>
                    </ul>
                }
            </div>
        </section>
    }
    @Html.Partial("_IndexSections")
}
